<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Class与style绑定</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
    <!-- 对象语法 -->
    <div id="app" class="static" v-bind:class="{ active: isActive, 'text-danger': hasError   }">
        hello Vue
        <div v-bind:class="classObject"></div>
    </div>
    <!-- 数组语法 -->
    <div id="app2">
        <div v-bind:class="[activeClass, errorClass]"></div>
    <!-- 三元运算 -->
    <div v-bind:class="[isActive ? activeClass: '', errorClass]"></div>
    </div>
    <!-- 绑定内联样式 -->
    <div id="app3">
        <div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }">
            我爱闽大
        </div>
        <!-- 样式对象 -->
        <div v-bind:style="styleObject">
            我的闽大是最好的
        </div>
        <!-- 数组语法 -->
        <div v-bind:style="[baseStyles, overridingStyles]">
            中国福建省龙岩市闽西职业技术学院
        </div>
        <!-- 多重值 -->
        <div :style="{ display: ['-webkit-box', '-ms-flexbox', 'flex'] }">中国</div>
    </div>
</body>
<script type="text/javascript">
    // 对象语法
    const app = new Vue({
        el: '#app',
        data: {
            isActive: true,
            hasError: true,
            error: null,
            // classObject: {
            //     active: true,
            //     'text-danger': false
            // }
        },
        computed: {
            classObject: function(){
                return {
                    active: this.isActive && !this.error,
                    'text-danger': this.error && this.error.type === 'fatal'
                }
            }
        }
    })
    // 数组和三元
    const app2 = new Vue({
        el: '#app2',
        data: {
            isActive: true,
            activeClass: 'active',
            errorClass: 'text-danger'
        }
    })
    // 绑定内联样式
    var app3 = new Vue({
        el: '#app3',
        data: {
            activeColor: 'red',
            fontSize: 30,
        // 绑定样式对象
            styleObject:{
                color: 'red',
                fontSize: '13px'
            },
            baseStyles: {
                color: 'blue',
                fontSize: '16px'
            },
            overridingStyles: {
                backgroundColor: 'lightgray',
                fontSize: '20px'
            }
        }
    })
  
    
</script>
<style>
    .active {   
        background-color: aquamarine;
    }
</style>
</html>